<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('服务商数据统计列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>日期：</label>
                                <input name="belong_date"  type="text"  id="laydate-belong_date" placeholder="月份"/>
                            </li>

                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-warning" onclick="exportByMonth()" shiro:hasPermission="agentDateCen:agentDateCen:exportByMonth">
                    <i class="fa fa-download"></i> 导出
                </a>
                <a class="btn btn-warning" onclick="exportDetail()" shiro:hasPermission="agentDateCen:agentDateCen:exportByMonth">
                    <i class="fa fa-download"></i> 导出明细
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table" class="table text-nowrap"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "agentDateCen/agentDateCen";

        $(function() {
            var options = {
                url: prefix + "/silentMerByMonth",
                exportUrl: prefix + "/export",
                modalName: "沉默商户按月数据统计",
                columns: [
                {
                    field: 'MER_SILENT_NUM',
                    title: '沉默商户数'
                },
                {
                    field: 'BELONG_DATE',
                    title: '月份'
                },]
            };
            $.table.init(options);
            layui.use('laydate', function() {
                var laydate = layui.laydate;
                laydate.render({
                    elem: '#laydate-belong_date',
                    type: 'month',
                    trigger: 'click'
                });
            });
        });
        function exportByMonth() {
            $.modal.loading("正在导出数据，请稍后...");
            $.post(prefix+"/exportByMonth", {"belong_date":$("#laydate-belong_date").val()}, function(result) {
                if (result.code == web_status.SUCCESS) {
                    window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
                } else if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                } else {
                    $.modal.alertError(result.msg);
                }
                $.modal.closeLoading();
            });
        }


        function exportDetail() {
            var belongDate = $("input[name='belong_date']").val();
            if (belongDate.length == '0'){
                $.modal.alertWarning("请选择日期")
                return;
            }
            $.modal.loading("正在导出数据，请稍后...");
            $.post(ctx + "merchantInfo/total/export", {"status":"2","currentDateTime":belongDate}, function(result) {
                if (result.code == web_status.SUCCESS) {
                    window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
                } else if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                } else {
                    $.modal.alertError(result.msg);
                }
                $.modal.closeLoading();
            });
        }
    </script>
</body>
</html>